package com.hopu.blb_erp.controller;

import com.hopu.blb_erp.entity.*;
import com.hopu.blb_erp.mapper.CargoMapper;
import com.hopu.blb_erp.service.CargoService;
import com.hopu.blb_erp.service.IProductService;
import com.hopu.blb_erp.service.TMenuService;
import com.hopu.blb_erp.service.TWarningService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@Api
@RestController
public class TWaringController {
    @Autowired
    private CargoService cargoService;
    @Autowired
    private TMenuService tMenuService;
    @Autowired
    private IProductService tProductService;
    @Autowired
    private TWarningService tWarningService;

//更新数据
@PutMapping("/twarnings")
public ResponseEntity<String> modifyMenu(@RequestBody TWarning  tWarnings){
       tWarningService.saveOrUpdate(tWarnings);
       return ResponseEntity.ok("ok");
}
  @ApiOperation("查询所有仓库")
  @GetMapping("/twarningse/{menuId}")
 public ResponseEntity<TWarning> find(@PathVariable("menuId") String menuId){
    TWarning tWarning = tWarningService.selectNums(menuId);
    return ResponseEntity.ok(tWarning);
}
    @ApiOperation("查询所有仓库")
    @GetMapping("/warnings")
    public ResponseEntity<List<TMenu>> findAll(){
        List<TMenu> list = tMenuService.list();
        return ResponseEntity.ok(list);
    }
    @ApiOperation("查询所有产品")
    @GetMapping("/product")
    public ResponseEntity<List<Product>> findAlls(){
        List<Product> list = tProductService.list();
        return ResponseEntity.ok(list);
    }
    @ApiOperation("分页库存模糊查询")
    @GetMapping("/warning/{current}/{pageSize}")
    public ResponseEntity<PageEntity<TCargo>> findPage(@PathVariable("current") Integer current,
                                                         @PathVariable("pageSize") Integer pageSize,
                                                          String menuId, String product, Integer productNum){
        PageEntity<TCargo> pages = cargoService.findPages(current, pageSize, menuId, product, productNum);
        return ResponseEntity.ok(pages);
    }
}
